#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import tkinter as tk
from tkinter import filedialog, messagebox, ttk
import os
import sys
from PIL import Image, ImageDraw, ImageFont, ImageTk
import datetime
import math

class WatermarkGUI:
    def __init__(self, root):
        self.root = root
        self.root.title("高级水印生成器")
        self.root.geometry("800x700")
        
        # 水印类型
        self.watermark_type = tk.StringVar(value="text")
        
        # 文字水印参数
        self.watermark_text = tk.StringVar(value="水印文字")
        self.font_size = tk.IntVar(value=36)
        self.color = tk.StringVar(value="white")
        self.opacity = tk.IntVar(value=128)
        self.rotation = tk.IntVar(value=0)
        self.stroke_width = tk.IntVar(value=0)
        self.stroke_color = tk.StringVar(value="black")
        
        # 图片水印参数
        self.image_watermark_path = tk.StringVar()
        
        # 位置选项
        self.position = tk.StringVar(value="bottom-right")
        self.positions = {
            "左上": "top-left",
            "上方": "top",
            "右上": "top-right",
            "左侧": "left",
            "中心": "center",
            "右侧": "right",
            "左下": "bottom-left",
            "下方": "bottom",
            "右下": "bottom-right"
        }
        
        # 高级布局参数
        self.margin_x = tk.IntVar(value=10)
        self.margin_y = tk.IntVar(value=10)
        self.use_percentage = tk.BooleanVar(value=False)
        self.percentage_x = tk.IntVar(value=5)
        self.percentage_y = tk.IntVar(value=5)
        
        # 批量处理参数
        self.recursive = tk.BooleanVar(value=False)
        self.output_prefix = tk.StringVar(value="")
        self.output_suffix = tk.StringVar(value="_watermarked")
        
        # 输入输出路径
        self.input_path = tk.StringVar()
        self.output_path = tk.StringVar()
        
        # 预览相关
        self.preview_image = None
        self.original_image = None
        
        self.create_widgets()
        
    def create_widgets(self):
        # 创建notebook用于分页
        notebook = ttk.Notebook(self.root)
        notebook.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
        
        # 主要设置页面
        main_frame = ttk.Frame(notebook, padding="10")
        notebook.add(main_frame, text="主要设置")
        
        # 水印类型选择
        ttk.Label(main_frame, text="水印类型:").grid(row=0, column=0, sticky=tk.W, pady=5)
        type_frame = ttk.Frame(main_frame)
        type_frame.grid(row=0, column=1, columnspan=2, sticky=(tk.W, tk.E), pady=5)
        ttk.Radiobutton(type_frame, text="文字水印", variable=self.watermark_type, value="text", 
                       command=self.switch_watermark_type).pack(side=tk.LEFT)
        ttk.Radiobutton(type_frame, text="图片水印", variable=self.watermark_type, value="image", 
                       command=self.switch_watermark_type).pack(side=tk.LEFT, padx=(10, 0))
        
        # 文字水印设置
        self.text_frame = ttk.LabelFrame(main_frame, text="文字水印设置", padding="10")
        self.text_frame.grid(row=1, column=0, columnspan=3, sticky=(tk.W, tk.E), pady=5)
        
        ttk.Label(self.text_frame, text="水印文字:").grid(row=0, column=0, sticky=tk.W, pady=2)
        ttk.Entry(self.text_frame, textvariable=self.watermark_text, width=30).grid(row=0, column=1, columnspan=3, sticky=(tk.W, tk.E), pady=2)
        
        ttk.Label(self.text_frame, text="字体大小:").grid(row=1, column=0, sticky=tk.W, pady=2)
        ttk.Scale(self.text_frame, from_=10, to=100, variable=self.font_size, orient=tk.HORIZONTAL).grid(row=1, column=1, sticky=(tk.W, tk.E), pady=2)
        ttk.Label(self.text_frame, textvariable=self.font_size).grid(row=1, column=2, pady=2)
        
        ttk.Label(self.text_frame, text="颜色:").grid(row=2, column=0, sticky=tk.W, pady=2)
        color_combo = ttk.Combobox(self.text_frame, textvariable=self.color,
                                  values=["white", "black", "red", "blue", "green", "yellow", "purple"], state="readonly", width=15)
        color_combo.grid(row=2, column=1, sticky=tk.W, pady=2)
        color_combo.current(0)
        
        ttk.Label(self.text_frame, text="透明度:").grid(row=3, column=0, sticky=tk.W, pady=2)
        ttk.Scale(self.text_frame, from_=0, to=255, variable=self.opacity, orient=tk.HORIZONTAL).grid(row=3, column=1, sticky=(tk.W, tk.E), pady=2)
        ttk.Label(self.text_frame, textvariable=self.opacity).grid(row=3, column=2, pady=2)
        
        ttk.Label(self.text_frame, text="旋转角度:").grid(row=4, column=0, sticky=tk.W, pady=2)
        ttk.Scale(self.text_frame, from_=-180, to=180, variable=self.rotation, orient=tk.HORIZONTAL).grid(row=4, column=1, sticky=(tk.W, tk.E), pady=2)
        ttk.Label(self.text_frame, textvariable=self.rotation).grid(row=4, column=2, pady=2)
        
        ttk.Label(self.text_frame, text="描边宽度:").grid(row=5, column=0, sticky=tk.W, pady=2)
        ttk.Scale(self.text_frame, from_=0, to=10, variable=self.stroke_width, orient=tk.HORIZONTAL).grid(row=5, column=1, sticky=(tk.W, tk.E), pady=2)
        ttk.Label(self.text_frame, textvariable=self.stroke_width).grid(row=5, column=2, pady=2)
        
        ttk.Label(self.text_frame, text="描边颜色:").grid(row=6, column=0, sticky=tk.W, pady=2)
        stroke_combo = ttk.Combobox(self.text_frame, textvariable=self.stroke_color,
                                   values=["black", "white", "red", "blue", "green", "yellow", "purple"], state="readonly", width=15)
        stroke_combo.grid(row=6, column=1, sticky=tk.W, pady=2)
        stroke_combo.current(0)
        
        # 图片水印设置
        self.image_frame = ttk.LabelFrame(main_frame, text="图片水印设置", padding="10")
        self.image_frame.grid(row=1, column=0, columnspan=3, sticky=(tk.W, tk.E), pady=5)
        self.image_frame.grid_remove()  # 默认隐藏
        
        ttk.Label(self.image_frame, text="图片路径:").grid(row=0, column=0, sticky=tk.W, pady=2)
        ttk.Entry(self.image_frame, textvariable=self.image_watermark_path, width=30).grid(row=0, column=1, sticky=(tk.W, tk.E), pady=2)
        ttk.Button(self.image_frame, text="浏览", command=self.browse_watermark_image).grid(row=0, column=2, padx=(5, 0), pady=2)
        
        # 位置设置
        position_frame = ttk.LabelFrame(main_frame, text="位置设置", padding="10")
        position_frame.grid(row=2, column=0, columnspan=3, sticky=(tk.W, tk.E), pady=5)
        
        ttk.Label(position_frame, text="位置:").grid(row=0, column=0, sticky=tk.W, pady=2)
        position_combo = ttk.Combobox(position_frame, textvariable=self.position, 
                                     values=list(self.positions.keys()), state="readonly")
        position_combo.grid(row=0, column=1, sticky=tk.W, pady=2)
        position_combo.current(8)  # 默认选择右下角
        
        # 边距设置
        margin_frame = ttk.LabelFrame(position_frame, text="边距设置", padding="5")
        margin_frame.grid(row=1, column=0, columnspan=2, sticky=(tk.W, tk.E), pady=(10, 0))
        
        ttk.Checkbutton(margin_frame, text="使用百分比", variable=self.use_percentage).grid(row=0, column=0, columnspan=2, sticky=tk.W)
        
        ttk.Label(margin_frame, text="X边距:").grid(row=1, column=0, sticky=tk.W, pady=2)
        ttk.Entry(margin_frame, textvariable=self.margin_x, width=10).grid(row=1, column=1, sticky=tk.W, pady=2, padx=(5, 0))
        ttk.Label(margin_frame, text="px").grid(row=1, column=2, sticky=tk.W, pady=2)
        ttk.Scale(margin_frame, from_=0, to=100, variable=self.percentage_x, orient=tk.HORIZONTAL).grid(row=1, column=3, sticky=(tk.W, tk.E), pady=2)
        ttk.Label(margin_frame, textvariable=self.percentage_x).grid(row=1, column=4, pady=2)
        ttk.Label(margin_frame, text="%").grid(row=1, column=5, sticky=tk.W, pady=2)
        
        ttk.Label(margin_frame, text="Y边距:").grid(row=2, column=0, sticky=tk.W, pady=2)
        ttk.Entry(margin_frame, textvariable=self.margin_y, width=10).grid(row=2, column=1, sticky=tk.W, pady=2, padx=(5, 0))
        ttk.Label(margin_frame, text="px").grid(row=2, column=2, sticky=tk.W, pady=2)
        ttk.Scale(margin_frame, from_=0, to=100, variable=self.percentage_y, orient=tk.HORIZONTAL).grid(row=2, column=3, sticky=(tk.W, tk.E), pady=2)
        ttk.Label(margin_frame, textvariable=self.percentage_y).grid(row=2, column=4, pady=2)
        ttk.Label(margin_frame, text="%").grid(row=2, column=5, sticky=tk.W, pady=2)
        
        # 路径设置
        path_frame = ttk.LabelFrame(main_frame, text="路径设置", padding="10")
        path_frame.grid(row=3, column=0, columnspan=3, sticky=(tk.W, tk.E), pady=5)
        
        ttk.Label(path_frame, text="输入目录:").grid(row=0, column=0, sticky=tk.W, pady=2)
        ttk.Entry(path_frame, textvariable=self.input_path, width=30).grid(row=0, column=1, sticky=(tk.W, tk.E), pady=2)
        ttk.Button(path_frame, text="浏览", command=self.browse_input).grid(row=0, column=2, padx=(5, 0), pady=2)
        
        ttk.Label(path_frame, text="输出目录:").grid(row=1, column=0, sticky=tk.W, pady=2)
        ttk.Entry(path_frame, textvariable=self.output_path, width=30).grid(row=1, column=1, sticky=(tk.W, tk.E), pady=2)
        ttk.Button(path_frame, text="浏览", command=self.browse_output).grid(row=1, column=2, padx=(5, 0), pady=2)
        
        # 批量处理设置
        batch_frame = ttk.LabelFrame(main_frame, text="批量处理设置", padding="10")
        batch_frame.grid(row=4, column=0, columnspan=3, sticky=(tk.W, tk.E), pady=5)
        
        ttk.Checkbutton(batch_frame, text="递归处理子目录", variable=self.recursive).grid(row=0, column=0, sticky=tk.W)
        
        ttk.Label(batch_frame, text="输出文件前缀:").grid(row=1, column=0, sticky=tk.W, pady=2)
        ttk.Entry(batch_frame, textvariable=self.output_prefix, width=15).grid(row=1, column=1, sticky=tk.W, pady=2, padx=(5, 0))
        
        ttk.Label(batch_frame, text="输出文件后缀:").grid(row=1, column=2, sticky=tk.W, pady=2, padx=(10, 0))
        ttk.Entry(batch_frame, textvariable=self.output_suffix, width=15).grid(row=1, column=3, sticky=tk.W, pady=2, padx=(5, 0))
        
        # 预览页面
        preview_frame = ttk.Frame(notebook, padding="10")
        notebook.add(preview_frame, text="预览")
        
        ttk.Label(preview_frame, text="选择图片进行预览:").pack(anchor=tk.W, pady=(0, 10))
        ttk.Button(preview_frame, text="选择图片", command=self.select_preview_image).pack(anchor=tk.W, pady=(0, 10))
        
        self.preview_label = ttk.Label(preview_frame)
        self.preview_label.pack(expand=True, fill=tk.BOTH)
        
        # 执行按钮
        button_frame = ttk.Frame(main_frame)
        button_frame.grid(row=5, column=0, columnspan=3, pady=20)
        
        ttk.Button(button_frame, text="添加水印", command=self.add_watermark).pack(side=tk.LEFT, padx=5)
        ttk.Button(button_frame, text="预览效果", command=self.preview_effect).pack(side=tk.LEFT, padx=5)
        ttk.Button(button_frame, text="退出", command=self.root.quit).pack(side=tk.LEFT, padx=5)
        
        # 进度条
        self.progress = ttk.Progressbar(main_frame, mode='indeterminate')
        self.progress.grid(row=6, column=0, columnspan=3, sticky=(tk.W, tk.E), pady=10)
        
        # 状态标签
        self.status_label = ttk.Label(main_frame, text="就绪")
        self.status_label.grid(row=7, column=0, columnspan=3, pady=5)
        
        # 配置列权重
        self.root.columnconfigure(0, weight=1)
        self.root.rowconfigure(0, weight=1)
        main_frame.columnconfigure(1, weight=1)
        self.text_frame.columnconfigure(1, weight=1)
        self.image_frame.columnconfigure(1, weight=1)
        path_frame.columnconfigure(1, weight=1)
        
    def switch_watermark_type(self):
        if self.watermark_type.get() == "text":
            self.text_frame.grid()
            self.image_frame.grid_remove()
        else:
            self.text_frame.grid_remove()
            self.image_frame.grid()
            
    def browse_watermark_image(self):
        path = filedialog.askopenfilename(filetypes=[("Image files", "*.png *.jpg *.jpeg *.gif *.bmp")])
        if path:
            self.image_watermark_path.set(path)
            
    def browse_input(self):
        path = filedialog.askdirectory()
        if path:
            self.input_path.set(path)
            
    def browse_output(self):
        path = filedialog.askdirectory()
        if path:
            self.output_path.set(path)
            
    def select_preview_image(self):
        path = filedialog.askopenfilename(filetypes=[("Image files", "*.png *.jpg *.jpeg *.bmp *.tiff")])
        if path:
            try:
                self.original_image = Image.open(path)
                # 调整图片大小以适应预览区域
                preview_width = 600
                preview_height = 400
                img_width, img_height = self.original_image.size
                ratio = min(preview_width/img_width, preview_height/img_height)
                new_width = int(img_width * ratio)
                new_height = int(img_height * ratio)
                resized_image = self.original_image.resize((new_width, new_height), Image.LANCZOS)
                self.preview_image = ImageTk.PhotoImage(resized_image)
                self.preview_label.configure(image=self.preview_image)
                self.preview_label.image = self.preview_image
            except Exception as e:
                messagebox.showerror("错误", f"无法加载图片: {str(e)}")
                
    def preview_effect(self):
        if not self.original_image:
            messagebox.showwarning("警告", "请先选择预览图片")
            return
            
        try:
            # 创建水印效果预览
            preview_image = self.original_image.copy()
            if self.watermark_type.get() == "text":
                self.add_text_watermark_to_image(preview_image)
            else:
                self.add_image_watermark_to_image(preview_image)
                
            # 调整图片大小以适应预览区域
            preview_width = 600
            preview_height = 400
            img_width, img_height = preview_image.size
            ratio = min(preview_width/img_width, preview_height/img_height)
            new_width = int(img_width * ratio)
            new_height = int(img_height * ratio)
            resized_image = preview_image.resize((new_width, new_height), Image.LANCZOS)
            self.preview_image = ImageTk.PhotoImage(resized_image)
            self.preview_label.configure(image=self.preview_image)
            self.preview_label.image = self.preview_image
            self.status_label.config(text="预览已更新")
        except Exception as e:
            messagebox.showerror("错误", f"预览失败: {str(e)}")
            
    def add_watermark(self):
        input_path = self.input_path.get()
        output_path = self.output_path.get()
        
        if not input_path or not output_path:
            messagebox.showerror("错误", "请选择输入和输出目录")
            return
            
        if not os.path.exists(input_path):
            messagebox.showerror("错误", "输入目录不存在")
            return
            
        if not os.path.exists(output_path):
            os.makedirs(output_path)
            
        self.progress.start()
        self.status_label.config(text="正在处理...")
        self.root.update()
        
        try:
            self.process_images(input_path, output_path)
            self.progress.stop()
            self.status_label.config(text="处理完成")
            messagebox.showinfo("完成", "水印添加完成")
        except Exception as e:
            self.progress.stop()
            self.status_label.config(text="处理失败")
            messagebox.showerror("错误", f"处理过程中出现错误:\n{str(e)}")
            
    def process_images(self, input_path, output_path):
        # 支持的图片格式
        image_extensions = ('.png', '.jpg', '.jpeg', '.bmp', '.tiff')
        
        # 获取所有图片文件
        image_files = []
        if self.recursive.get():
            for root, dirs, files in os.walk(input_path):
                for file in files:
                    if file.lower().endswith(image_extensions):
                        image_files.append(os.path.join(root, file))
        else:
            image_files = [f for f in os.listdir(input_path) 
                          if os.path.isfile(os.path.join(input_path, f)) and f.lower().endswith(image_extensions)]
        
        total_files = len(image_files)
        for i, image_file in enumerate(image_files):
            if self.recursive.get():
                relative_path = os.path.relpath(image_file, input_path)
                input_file = image_file
                output_file = os.path.join(output_path, self.output_prefix.get() + 
                                          os.path.splitext(relative_path)[0] + 
                                          self.output_suffix.get() + 
                                          os.path.splitext(relative_path)[1])
                # 确保输出目录存在
                output_dir = os.path.dirname(output_file)
                if not os.path.exists(output_dir):
                    os.makedirs(output_dir)
            else:
                input_file = os.path.join(input_path, image_file)
                name, ext = os.path.splitext(image_file)
                output_file = os.path.join(output_path, self.output_prefix.get() + name + self.output_suffix.get() + ext)
            
            try:
                self.add_watermark_to_image(input_file, output_file)
                # 更新进度
                self.status_label.config(text=f"正在处理: {i+1}/{total_files}")
                self.root.update()
            except Exception as e:
                print(f"处理 {image_file} 时出错: {str(e)}")
                
    def add_watermark_to_image(self, input_file, output_file):
        # 打开图片
        image = Image.open(input_file).convert("RGBA")
        
        if self.watermark_type.get() == "text":
            self.add_text_watermark_to_image(image)
        else:
            self.add_image_watermark_to_image(image)
        
        # 保存图片
        if output_file.lower().endswith('.png'):
            image.save(output_file, "PNG")
        else:
            # 转换为RGB模式以保存为JPEG等格式
            rgb_image = image.convert('RGB')
            rgb_image.save(output_file)
            
    def add_text_watermark_to_image(self, image):
        # 创建水印
        txt = Image.new('RGBA', image.size, (255,255,255,0))
        draw = ImageDraw.Draw(txt)
        
        # 尝试使用系统字体，如果失败则使用默认字体
        try:
            font = ImageFont.truetype("arial.ttf", self.font_size.get())
        except:
            font = ImageFont.load_default()
        
        # 获取文本尺寸
        text = self.watermark_text.get()
        bbox = draw.textbbox((0, 0), text, font=font)
        text_width = bbox[2] - bbox[0]
        text_height = bbox[3] - bbox[1]
        
        # 根据选择的位置确定水印位置
        position_key = self.position.get()
        position_value = self.positions.get(position_key, "bottom-right")
        
        # 计算边距
        margin_x = self.margin_x.get()
        margin_y = self.margin_y.get()
        if self.use_percentage.get():
            margin_x = int(image.size[0] * self.percentage_x.get() / 100)
            margin_y = int(image.size[1] * self.percentage_y.get() / 100)
        
        # 根据位置计算坐标
        if position_value == "top-left":
            x, y = margin_x, margin_y
        elif position_value == "top":
            x, y = (image.size[0] - text_width) // 2, margin_y
        elif position_value == "top-right":
            x, y = image.size[0] - text_width - margin_x, margin_y
        elif position_value == "left":
            x, y = margin_x, (image.size[1] - text_height) // 2
        elif position_value == "center":
            x, y = (image.size[0] - text_width) // 2, (image.size[1] - text_height) // 2
        elif position_value == "right":
            x, y = image.size[0] - text_width - margin_x, (image.size[1] - text_height) // 2
        elif position_value == "bottom-left":
            x, y = margin_x, image.size[1] - text_height - margin_y
        elif position_value == "bottom":
            x, y = (image.size[0] - text_width) // 2, image.size[1] - text_height - margin_y
        elif position_value == "bottom-right":
            x, y = image.size[0] - text_width - margin_x, image.size[1] - text_height - margin_y
        else:  # 默认右下角
            x, y = image.size[0] - text_width - margin_x, image.size[1] - text_height - margin_y
        
        # 绘制描边
        stroke_width = self.stroke_width.get()
        if stroke_width > 0:
            stroke_color = self.get_color_value(self.stroke_color.get())
            for dx in range(-stroke_width, stroke_width+1):
                for dy in range(-stroke_width, stroke_width+1):
                    if dx != 0 or dy != 0:
                        draw.text((x+dx, y+dy), text, 
                                 fill=(stroke_color[0], stroke_color[1], stroke_color[2], self.opacity.get()), 
                                 font=font)
        
        # 绘制水印
        color = self.get_color_value(self.color.get())
        opacity = self.opacity.get()
        draw.text((x, y), text, 
                 fill=(color[0], color[1], color[2], opacity), 
                 font=font)
        
        # 如果有旋转角度，则旋转水印
        rotation = self.rotation.get()
        if rotation != 0:
            # 创建一个足够大的新图像来容纳旋转后的水印
            rotated = txt.rotate(rotation, expand=1)
            # 创建一个新的图像来放置旋转后的水印
            txt = Image.new('RGBA', image.size, (255,255,255,0))
            # 计算旋转后水印的位置
            txt_width, txt_height = rotated.size
            pos_x = (image.size[0] - txt_width) // 2
            pos_y = (image.size[1] - txt_height) // 2
            txt.paste(rotated, (pos_x, pos_y), rotated)
        
        # 合并水印和图片
        watermarked = Image.alpha_composite(image, txt)
        image.paste(watermarked, (0, 0))
        
    def add_image_watermark_to_image(self, image):
        if not self.image_watermark_path.get():
            return
            
        try:
            # 加载水印图片
            watermark = Image.open(self.image_watermark_path.get()).convert("RGBA")
            
            # 调整水印大小（简单按比例缩放）
            # 这里可以进一步优化，比如根据原图大小自动调整水印大小
            watermark_width = int(image.size[0] * 0.2)  # 水印宽度为原图的20%
            watermark_height = int(watermark.size[1] * (watermark_width / watermark.size[0]))
            watermark = watermark.resize((watermark_width, watermark_height), Image.LANCZOS)
            
            # 根据选择的位置确定水印位置
            position_key = self.position.get()
            position_value = self.positions.get(position_key, "bottom-right")
            
            # 计算边距
            margin_x = self.margin_x.get()
            margin_y = self.margin_y.get()
            if self.use_percentage.get():
                margin_x = int(image.size[0] * self.percentage_x.get() / 100)
                margin_y = int(image.size[1] * self.percentage_y.get() / 100)
            
            # 根据位置计算坐标
            if position_value == "top-left":
                x, y = margin_x, margin_y
            elif position_value == "top":
                x, y = (image.size[0] - watermark.size[0]) // 2, margin_y
            elif position_value == "top-right":
                x, y = image.size[0] - watermark.size[0] - margin_x, margin_y
            elif position_value == "left":
                x, y = margin_x, (image.size[1] - watermark.size[1]) // 2
            elif position_value == "center":
                x, y = (image.size[0] - watermark.size[0]) // 2, (image.size[1] - watermark.size[1]) // 2
            elif position_value == "right":
                x, y = image.size[0] - watermark.size[0] - margin_x, (image.size[1] - watermark.size[1]) // 2
            elif position_value == "bottom-left":
                x, y = margin_x, image.size[1] - watermark.size[1] - margin_y
            elif position_value == "bottom":
                x, y = (image.size[0] - watermark.size[0]) // 2, image.size[1] - watermark.size[1] - margin_y
            elif position_value == "bottom-right":
                x, y = image.size[0] - watermark.size[0] - margin_x, image.size[1] - watermark.size[1] - margin_y
            else:  # 默认右下角
                x, y = image.size[0] - watermark.size[0] - margin_x, image.size[1] - watermark.size[1] - margin_y
            
            # 调整透明度
            if self.opacity.get() < 255:
                # 创建透明度调整后的水印
                alpha = watermark.split()[-1]  # 获取alpha通道
                alpha = alpha.point(lambda p: min(p, self.opacity.get()))
                watermark.putalpha(alpha)
            
            # 将水印粘贴到图像上
            image.paste(watermark, (x, y), watermark)
        except Exception as e:
            print(f"添加图片水印时出错: {str(e)}")
            
    def get_color_value(self, color_name):
        colors = {
            "white": (255, 255, 255),
            "black": (0, 0, 0),
            "red": (255, 0, 0),
            "blue": (0, 0, 255),
            "green": (0, 255, 0),
            "yellow": (255, 255, 0),
            "purple": (128, 0, 128)
        }
        return colors.get(color_name, (255, 255, 255))

def main():
    root = tk.Tk()
    app = WatermarkGUI(root)
    root.mainloop()

if __name__ == "__main__":
    main()